#include "Sierpinski.hpp" // also defines Point
#include <allegro.h>
#include <cstdlib>
#include <ctime>
#include <iostream>

using namespace std;

int main() {
    Sierpinski s;
    Point p;

    // init Allegro display {{{
    allegro_init();
    install_keyboard();
    // install_mouse();
    // install_timer();

    set_color_depth(32);
    if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0)) {
        set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
        allegro_message("Graphics initialization failed\n%s\n", allegro_error);
        cout << "Graphics initialization failed:" << std::endl << allegro_error << std::endl;
        return -1;
    }
    // }}}

    srand(time(NULL));

    // draw vertices {{{
    for (int i = 0; i < 3; i++)
        circle(screen, int(s.pts[i].x * double(SCREEN_H-20) + 10), int(s.pts[i].y * double(SCREEN_H - 20) + 10),
                3, makecol(155, 255, 255));
    // }}}

    // main loop {{{
    while (!(key[KEY_Q] || key[KEY_ESC])) {
        p = s.genPoint(); // x, y are double where 1 is height of the whole triangle
         
        putpixel(screen, int(p.x * (SCREEN_H-20) + 10), int(p.y * (SCREEN_H - 20) + 10),
            makecol(rand()%156 + 100, rand()%156 + 100, rand()%156 + 100));

        rest(1);
    } // }}}

    return 0;
}
END_OF_MAIN();
